import { timeonly } from '../../utils/util'
Page({
  data: {
    flag: false,
  },
  onLoad() {
    this._getUser()
  },
  async _getUser() {
    let {
      code,
      data: { last_sign },
    } = await wx.requestAsync({
      url: '/user/info',
    })
    if (code == 0) {
      console.log(last_sign)
      console.log(timeonly(0))
      if (last_sign > timeonly(0)) {
        this.setData({
          flag: true,
        })
      } else {
        this.setData({
          flag: false,
        })
      }
    }
  },
  async _sign() {
    let { code, msg } = await wx.requestAsync({
      url: '/sign',
    })
    if (code == 0) {
      this.setData({
        flag: true,
      })
      wx.showToast({
        title: '签到成功',
        icon: 'none',
        duration: 2000,
      })
    } else {
      wx.showToast({
        title: msg,
        icon: 'none',
        duration: 2000,
      })
    }
  },
  // 个人资料
  _toinformation() {
    wx.navigateTo({
      url: '/pages/information/information',
    })
  },
  // 宝宝资料
  _tobaby() {
    wx.navigateTo({
      url: '/pages/baby/baby',
    })
  },
  // 预约课程
  _toreservationList() {
    wx.switchTab({
      url: '/pages/service/service',
    })
  },
})
